package com.second.controller.groupon;

import com.second.model.pojo.FGoods;
import com.second.model.pojo.FGoodsPicture;
import com.second.model.pojo.FShop;
import com.second.service.IFGoodsPictureService;
import com.second.service.IFGoodsService;
import com.second.service.IFShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 本类用来演示: 团购券详情
 *
 * @author: MuTing
 * @date: 2022-04-14 21:43
 */

@Controller
@RequestMapping("groupon")
public class GrouponController {

    @Autowired
    private IFShopService shopService;

    @Autowired
    private IFGoodsService goodsService;

    @Autowired
    private IFGoodsPictureService goodsPictureService;

    @GetMapping("enter/{shopId}/{goodId}")
    public String enter(@PathVariable(name = "goodId") Integer goodId,@PathVariable(name = "shopId") Integer shopId,
                         HttpServletRequest request){

        FShop fShop = shopService.getById(shopId);

        String coordinate = shopService.coordinate(shopId); //高德坐标

        FGoods fGood = goodsService.getGoodsById(goodId);

        FGoodsPicture fGoodsPicture = goodsPictureService.getGoodsPictureByGoodId(goodId);

        List<FGoods> fGoodList = goodsService.findAllByShopId(fGood.getShopId());

        request.setAttribute("coordinate",coordinate);
        request.setAttribute("fShop",fShop);
        request.setAttribute("fGood",fGood);
        request.setAttribute("fGoodList",fGoodList);
        request.setAttribute("fGoodsPicture",fGoodsPicture);

        return "jsp/groupon/groupon";
    }
}
